package com.example.photography.adapter.focus;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.photography.R;
import com.example.photography.adapter.community.Community_ActAdapter;
import com.example.photography.bean.FocusBean;
import com.example.photography.util.Util;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class IntAdpter extends RecyclerView.Adapter<IntAdpter.ViewHolder> {
    private final Context context;
    private List<FocusBean.DataBean.RelationsBean> relationsBeans;

    public IntAdpter(Context context, List<FocusBean.DataBean.RelationsBean> relationsBeans) {
        this.context = context;
        this.relationsBeans = relationsBeans;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_user_image, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;

    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        FocusBean.DataBean.RelationsBean relationsBean= relationsBeans.get(position);
        holder.svImage.setImageURI(Uri.parse(relationsBean.getImage()));
        holder.tvIdentify.setText(relationsBean.getIdentity());
        holder.tvName.setText(relationsBean.getName());
        holder.tvFocus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Util.showToast(context,"关注成功");
            }
        });
    }

    @Override
    public int getItemCount() {
        return relationsBeans == null?0:relationsBeans.size();
    }

    static
    class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.sv_image)
        SimpleDraweeView svImage;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_identify)
        TextView tvIdentify;
        @BindView(R.id.tv_focus)
        TextView tvFocus;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
